﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      ACR Common Helper
// Created By:     TingRong Shi (trshi@wicresoft.com)
// Created Date:   2011-2-23
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASBCC.Database.EntityFramework;

namespace ASB.CC.Business.ACR
{
    public static class CommonHelper
    {
        /// <summary>
        /// 判断用户是否为ACR管理员
        /// </summary>
        public static bool IsACRAdmin(string[] roles)
        {
            using (var dc = new CCEntities())
            {
                foreach (var role in roles)
                {
                    if (!String.IsNullOrEmpty(role))
                    {
                        int role1 = int.Parse(role);
                        if (dc.Roles.Where(p => p.RoleID == role1 && p.BelongsTo == "ACR" && p.IsAdmin == true).Count() > 0)
                            return true;
                        else
                            continue;
                    }
                }
                return false;
            }
        }

        public static bool IsCreator(string id, string name)
        {
            using (var dc = new CCEntities())
            {
                if (!String.IsNullOrEmpty(id))
                {
                    int issueID = int.Parse(id);
                    var user = dc.IssueTracker_Users.First(p => p.UserName == name);
                    var issue = dc.IssueTracker_Issues.First(p => p.IssueId == issueID);
                    return user.UserId == issue.IssueCreatorId;
                }
                return true;
            }
        }

    }
}
